<template>
	<view class="page">
		<uni-nav-bar background-color="#00a9ff" title="修改密码" color="white" :fixed="true"
		  statusBar="true" left-icon="left" @clickLeft="back"/>
		
		<image src="../../static/logo.png" class="mainlogo"></image>

		<form class="passwordrst-form">
		<input class="input-item" type="text" placeholder="请输入昵称" v-model="nickname"
		 placeholder-style="color:rgba(162, 140, 156, 0.7); font-size:15px"/>
		 
		 <input class="input-item" type="number" placeholder="请输入账号" v-model="userid"
		  placeholder-style="color:rgba(162, 140, 156, 0.7); font-size:15px"/>

		<input class="input-item" type="text" password placeholder="请输入密码" v-model="password"
		 placeholder-style="color:rgba(162, 140, 156, 0.7); font-size:15px"/>
		 
		 <input class="input-item" type="text" password placeholder="请确认密码" v-model="confirmPassword"
		 placeholder-style="color:rgba(162, 140, 156, 0.7); font-size:15px"/>
		 
		 <!-- <view class="input-item">
		   <input type="password" v-model="" placeholder="请确认密码">
		 </view> -->     
		<button class="btn" @click="resetPassword">
			 <text space="emsp">确 定</text>
		</button>
		</form>
	</view>
</template>

<script>
import axios from 'axios';
export default {
  data() {
    return {
      userid: '',
      password: '',
      confirmPassword: '',
      nickname: ''
    };
  },
  methods: {
	back(){
		uni.navigateBack()
	},
    async resetPassword() {
      if (!this.userid || !this.password || !this.nickname) {
        uni.showToast({
          title: '请填写完整信息',
          icon: 'none'
        });
        return;
      }
      if (this.password !== this.confirmPassword) {
        uni.showToast({
          title: '两次输入密码不一致',
          icon: 'none'
        });
        return;
      }
      try {
        const response = await axios.post('/api/user/resetPassword', {
          UserId: this.userid,
          Password: this.password,
          Nickname: this.nickname
        });
        const responseData = response.data;
        if (responseData.code === 200) {
          uni.showToast({
            title: responseData.message,
            icon: 'success'
          });
          uni.navigateTo({
            url: '/pages/login/login'
          });
        } else {
          uni.showToast({
            title: responseData.message,
            icon: 'none'
          });
        }
      } catch (error) {
        let errorMessage = '重设密码失败，请稍后再试';
        if (error.response) {
          if (error.response.status === 500) {
            errorMessage = error.response.data.message;
          }
        }
        uni.showToast({
          title: errorMessage,
          icon: 'none'
        });
      }
    }
  }
};
</script>
<style>
	
.mainlogo{
	width: 400rpx;
	height: 400rpx;
	display: flex;	
	margin:100rpx auto;
	border-radius: 100%;
}
.input-item{
	background-color: #fff;
	display: flex;
	width: 270px;
	height: 50px;
	margin: 20px auto;
	border: solid #06061f9 ;
	border-radius: 5px;
	padding-left: 20px;
	/*font-size: 20px;*/
	/*box-shadow: 3px 3px 2px rgba(168, 140, 158, 0.6);*/
	
}
</style>
